<?php

require 'facebook.php';
require 'config.inc.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => $fbconfig['app_id'],
  'secret' => $fbconfig['secret_key'],
  'cookie' => true,
));

$session = $facebook->getSession();
// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
  } catch (FacebookApiException $e) {
    echo "Somethings wrong";
  }
}


$id=$_POST["uid"];
$offset = $_POST["offset"];

if($offset=="" || $offset==NULL)
{
	$offset=0;
}
//echo print_r($ids);
$limit= $_POST["limit"];

$con = mysql_connect("localhost", "vatsav", "2T*vzcd");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("vatsav", $con);

if (!$db_selected) {
	die ('Cant use db : ' . mysql_error());
}
$limit++;

$result = mysql_query("select a.uid,a.friendid,a.groupid,b.group_name from invitations as a left join groups as b on a.groupid=b.groupid and a.uid=b.uid having a.friendid=".$id." LIMIT 0,".$limit);	
$limit--;
// Check result
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "<br/>";
   die($message);
}

$txt='';
while($row = mysql_fetch_array($result))
{
	$txt .= "<div class='topic-block' id='$row[0]-$row[2]'> <div class='small_header'>$row[3] group from <fb:name firstnameonly='true' uid='$row[0]' useyou='false' linked='false'></fb:name>:</div>
			<a class='topic-link' href='javascript:acceptInv($row[0],$row[1],$row[2],$offset)'>Accept</a>
			<a class='topic-link' href='javascript:cancelInv($row[0],$row[1],$row[2],$offset)'>Cancel</a></div>";
}
echo $txt;//.$row[0]."-".$row[3]';
?>
